<template>
  <view>
    <form>
      <xmInfo
        :projectno="dataInfo.projectno"
        :projectname="dataInfo.projectname"
      ></xmInfo>

      <view class="cu-form-group">
        <view class="title"
          ><text class="cuIcon-favorfill text-xs text-red"></text>处理日期</view
        >
        <picker
          mode="date"
          :value="dataInfo.dealwithdate ? dataInfo.dealwithdate :date"
          @change="DateChange"
        >
          <view class="picker">
            {{ dataInfo.dealwithdate ? dataInfo.dealwithdate : date }}
          </view>
        </picker>


      </view>
      <view class="cu-form-group" style="min-height: 0"></view>
      <view class="cu-bar bg-white">
        <view class="action"
          ><text class="cuIcon-favorfill text-xs text-red"></text>处理结果</view
        >
      </view>

      <view class="cu-form-group">
        <textarea
          maxlength="-1"
          :value="dataInfo.dealwithresult"
          @input="textareaAInput"
          placeholder="请输入处理结果"
        ></textarea>
      </view>
      <!-- v-if="flag" -->
      <view class="btn-group cu-bar foot" >
        <button class="cu-btn bg-green shadow-blur" @tap="submit">
          确认
        </button>
      </view>
    </form>
  </view>
</template>
  <script>
import addDetail from "./addDetail.vue";
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
  components: {
    addDetail,
    xmInfo,
  },
  data() {
    return {
      uploadOptions: {},
      switchA: false,
      date: new Date().toISOString().substring(0, 10),
      modalName: null,
      modalNameDetail: null,
      showAddDetail: false,
      dataInfo: {
        id: "",
        bpm: {},
        pmMaterialchecksList: [],
        selIds:''
      },
      isSubmitting: false,
      showButton: true,
      flag: hasPermission('btn:check:pmMaterialcheck:del'),
      x: 650, //x坐标
      y: 650, //y坐标
    };
  },
  onLoad(e) {
    console.log(e);
    if (!!e.xm) {
      this.dataInfo = JSON.parse(e.xm);
      this.dataInfo.selIds = e.id
      console.log(this.dataInfo, "dataInfo");
    }

  },
  methods: {

    submit() {
      this.dataInfo.dealwithdate = this.dataInfo.dealwithdate ? this.dataInfo.dealwithdate : this.date;
      if(!this.dataInfo.dealwithdate){
        this.$u.toast("处理日期必选");
        return;
      }
      if(!this.dataInfo.dealwithresult){
        this.$u.toast("处理结果必填");
        return;
      }
      console.log(this.dataInfo,'dataInfo');
      if (this.isSubmitting) {
        return;
      } else {
        this.isSubmitting = true;
        try {
          this.$u.api.zfgs
            .pmMaterialcheckFailed(this.dataInfo)
            .then((res) => {
              if (res.result == "true") {
                const itemContent = {
                  projectno: this.dataInfo.projectno,
                  projectname: this.dataInfo.projectname,
                };
                setTimeout(() => {
                  // uni.navigateTo({
                  //   url:
                  //     "/pages/zfgs/material/check/pmMaterialcheck/list?item=" +
                  //     JSON.stringify(itemContent),
                  // });
				  uni.navigateBack({
				  	delta: 1,
				  });
                }, 500);
              } else {
                this.$u.toast(res.message);
              }
            });
        } catch (error) {
          this.$u.toast(error.message);
        } finally {
          this.isSubmitting = false;
        }
      }
    },

    getCheckPmMaterialcheckForm(id) {
      this.$u.api.zfgs
        .checkPmMaterialcheckForm({
          id: id,
        })
        .then((res) => {
          console.log(res, "res===");
          this.dataInfo = res.pmMaterialcheck;
        });
    },

    DateChange(e) {
      this.dataInfo.dealwithdate = e.detail.value;
      this.$forceUpdate();
    },
    textareaAInput(e) {
      this.dataInfo.dealwithresult = e.detail.value;
    },

  },
};
</script>
  <style lang="scss" scoped>
$all_width: 140rpx;
$all_height: 140rpx;
.movable-area {
  z-index: 999;
  height: 97vh;
  width: 650rpx;
  // max-width: 1152rpx;
  // 固定在右边
  top: -150rpx;
  position: fixed;
  right: $all_width;
  // 固定在右下角
  pointer-events: none; //此处要加，鼠标事件可以渗透
  .movable-view {
    width: $all_width;
    height: $all_height;
    pointer-events: auto; //恢复鼠标事件
    .cu-bar {
      width: 320rpx;
    }
  }
}
.action {
  color: #303133;
}
.cu-form-group {
  flex-wrap: wrap;
}
.text-sl {
  font-size: 22px !important;
}
.cu-bar {
  min-height: 80px;
}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot {
  z-index: 997;
  background: #fff;
}
.green {
  color: green;
}
.input-align {
  text-align: right;
}
.sub-title {
  flex-grow: 1; /* 让右侧内容占据剩余空间 */
  max-width: 200px; /* 或其他合适的最大宽度，超过这个宽度时内容会换行 */
  word-break: break-word; /* 或 overflow-wrap: break-word; 允许单词在必要时断开以适应宽度 */
}
.xm-title {
  flex-basis: 100px; /* 或其他合适的固定宽度，用于左侧标题 */
  flex-shrink: 0; /* 防止标题在小屏幕下收缩 */
  overflow: hidden; /* 可选，防止内容溢出 */
}
.text-xsl {
  font-size: 60rpx !important;
}
.flex-end {
  display: flex;
  justify-content: flex-end;
}
.text-xs {
  font-size: 18rpx !important;
}
.cu-item {
  border: 1px solid #39b54a;
}
</style>